const rpn = require('request-promise-native');
const fs = require('fs');
var PDFParser = require("pdf2json");
var url = "http://www.cninfo.com.cn/new/hisAnnouncement/query";
var pdajsonlist = []
const useRequestPromiseNative = async () => {
    let options = {
        method: 'POST',
        uri: url,
        body: { // 这里定义你的body参数
        },
        json: true, // 这个看你的参数而定
    };
    let rpnbody = await rpn(options);
    pdajsonlist = rpnbody.announcements
    // 这里请求回来pdf文件地址之后下载pdf
    let pda = await rpn({
        method: 'Get',
        uri: 'http://static.cninfo.com.cn/finalpage/2022-02-17/1212386395.PDF',
        resolveWithFullResponse: true,
        Headers: {
            'Access- Control - Expose - Headers': 'Content - Disposition'
        },
        encoding: null,
        json: false, // 这个看你的参数而定
    });
    fs.writeFile('input.pdf', pda.body, function (err) {
    })
    let pdf = new PDFParser(this,1)
    pdf.loadPDF('./input.pdf')
    pdf.on("pdfParser_dataReady", pdfData => {
        console.log(pdf.getRawTextContent().replace(/刘洪/g,"<font color=red >刘洪</font>"))
    })
    console.log(pdajsonlist)
}
useRequestPromiseNative();